package com.onlyphoto.onlymall.mvp.presenter

import android.content.Context
import com.onlyphoto.onlymall.base.BaseNetworkResponse
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.CGoodsList
import com.onlyphoto.onlymall.mvp.model.MGoodsListImpl
import com.onlyphoto.onlymall.base.BasePresenter
import com.onlyphoto.onlymall.bean.request.GoodsCondition
import com.onlyphoto.onlymall.bean.response.GoodsBean


class PGoodsListImpl(mContext: Context, mView: CGoodsList.IVGoodsList) : BasePresenter<CGoodsList.IVGoodsList, MGoodsListImpl>(mContext, mView, MGoodsListImpl()), CGoodsList.IPGoodsList {
    override fun search(condition: GoodsCondition) {
        mModel.requestGoods(condition, object : BaseObserver<ArrayList<GoodsBean>>(mContext.get()){
            override fun onSuccess(data: ArrayList<GoodsBean>?, msg: String?) {
                mView.updateView()
                if (data == null) {
                    if (condition.page_num == 1) {
                        mView.showEmpty()
                    } else {
                        mView.showNoMore()
                    }
                }
                mView.searchSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<ArrayList<GoodsBean>>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }
}
